"""
聊天数据模式
"""

from typing import Optional, Dict, Any, List
from pydantic import BaseModel


class ModelSettings(BaseModel):
    """模型设置参数模式"""
    temperature: Optional[float] = None
    max_tokens: Optional[int] = None
    top_p: Optional[float] = None
    frequency_penalty: Optional[float] = None
    presence_penalty: Optional[float] = None
    context_count: Optional[int] = None
    streaming: Optional[bool] = None
    show_prompt: Optional[bool] = None
    use_serif_font: Optional[bool] = None
    auto_collapse_thinking: Optional[bool] = None
    show_message_outline: Optional[bool] = None
    message_style: Optional[str] = None
    multi_model_style: Optional[str] = None
    conversation_nav_button: Optional[str] = None
    message_font_size: Optional[str] = None


class ChatRequest(BaseModel):
    """聊天请求模式"""
    conversation_id: int
    message: str
    stream: bool = False
    knowledge_base_id: Optional[int] = None
    model_config_id: Optional[int] = None
    prompt_template_id: Optional[int] = None
    model_settings: Optional[ModelSettings] = None


class ChatResponse(BaseModel):
    """聊天响应模式"""
    success: bool
    message: str
    message_id: Optional[int] = None
    token_count: Optional[int] = None
    metadata: Optional[Dict[str, Any]] = None
    conversation_exceeded: bool = False


class ChatStreamResponse(BaseModel):
    """聊天流式响应模式"""
    type: str  # content, done, error
    content: Optional[str] = None
    token_count: Optional[int] = None
    message_id: Optional[int] = None
    total_tokens: Optional[int] = None
    error: Optional[str] = None


class ConversationCreateRequest(BaseModel):
    """创建对话请求模式"""
    title: Optional[str] = None
    model_config_id: Optional[int] = None
    knowledge_base_id: Optional[int] = None
    prompt_template_id: Optional[int] = None


class ConversationCreateResponse(BaseModel):
    """创建对话响应模式"""
    conversation_id: int
    title: str
    message: str


class MessageHistoryRequest(BaseModel):
    """消息历史请求模式"""
    conversation_id: int
    limit: Optional[int] = None


class MessageHistoryResponse(BaseModel):
    """消息历史响应模式"""
    messages: List[Dict[str, Any]]
    total_count: int
    conversation_id: int


class RAGChatRequest(BaseModel):
    """RAG聊天请求模式"""
    conversation_id: int
    message: str
    knowledge_base_id: int
    stream: bool = False
    top_k: int = 5


class RAGChatResponse(BaseModel):
    """RAG聊天响应模式"""
    success: bool
    message: str
    message_id: Optional[int] = None
    token_count: Optional[int] = None
    retrieved_documents: List[Dict[str, Any]] = []
    metadata: Optional[Dict[str, Any]] = None
